﻿using com.lythen.file.Security;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FileSecurityTool
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.processBar.Visibility = Visibility.Visible;
        }
        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("是否退出？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                this.Close();
            }
        }

        /// <summary>
        /// 重新生成密钥对
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateKeys_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 导入他人的公钥
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnImportKey_Click(object sender, RoutedEventArgs e)
        {

        }

        /// <summary>
        /// 导出自己的公钥
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExportPublicKey_Click(object sender, RoutedEventArgs e)
        {

        }
        /// <summary>
        /// 公钥管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnManagePublicKeys_Click(object sender, RoutedEventArgs e)
        {

        }
        /// <summary>
        /// 文件或文件夹加密
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEncryptFile_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtFileName.Text) && !string.IsNullOrEmpty(this.txtFolder.Text))
            {
                MessageBox.Show("文件和文件件，只能选一个。");
                return;
            }
            string savePath="";
            if (!string.IsNullOrEmpty(this.txtFileName.Text))
            {
                savePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.txtFileName.Text), System.IO.Path.GetFileNameWithoutExtension(this.txtFileName.Text) + ".dat");
                FileSecurity.EncryptFile(this.txtFileName.Text, savePath);
            }
            if (!string.IsNullOrEmpty(this.txtFolder.Text))
            {
                savePath = FileSecurity.ZipAndSignFile(this.txtFolder.Text);
            }
            string saveFolder = System.IO.Path.GetDirectoryName(savePath);
            Process.Start(saveFolder);
        }

        private void btnRestet_Click(object sender, RoutedEventArgs e)
        {
            this.txtFolder.Text = "";
            this.txtFileName.Text = "";
        }
    }
}
